package com.fare.taluo.core.domain.crawl.statistics;

import java.io.Serializable;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import com.dayatang.domain.InstanceFactory;
import com.dayatang.domain.QuerySettings;
import com.fare.taluo.core.domain.BaseEntity;

/**
 * @引擎统计-抓取统计报表
 * 
 */

@SuppressWarnings("serial")
@javax.persistence.Entity
@Table(name = "STATISTICS_TASK")
public class StatisticsTaskEntity extends BaseEntity<StatisticsTaskEntity> implements com.dayatang.domain.Entity{
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO, generator = FDC_SEQ_GEN)
	@SequenceGenerator(name = FDC_SEQ_GEN, sequenceName = FDC_SEQUENCE)
	@Column(name = "GRABCHANNEL")
	private String grabchannel;
	@Column(name = "GRABDATE")
	private String grabdate;
	@Column(name = "TOTAL")
	private Long total;
	@Column(name = "SUCCESS_NUM")
	private Long successNum;
	@Column(name = "FAIL_NUM")
	private Long failNum;
	@Column(name="ACTUAL_NUM")
	private Long actualNum;
	
	//各种失败原因的状态   -2表示      抓取失败
	//			   -3表示     解析失败  
	//			   -4表示    其他失败
	//             -10表示  未定义失败
	@Column(name="STATUS")
	private Long status;
	
	@Column(name="GRABCHANNEL_ID")
	private Long grabChannelID;
	
	
	@Column(name="byte_length")
	private Long allbyteLength;
	
	
	@Column(name="waiting")
	private Long waiting;
	
	@Column(name="starting")
	private long starting;
	
	
	public Long getAllbyteLength() {
		return allbyteLength;
	}
	public void setAllbyteLength(Long allbyteLength) {
		this.allbyteLength = allbyteLength;
	}
	public String getGrabchannel() {
		return grabchannel;
	}
	public void setGrabchannel(String grabchannel) {
		this.grabchannel = grabchannel;
	}
	public String getGrabdate() {
		return grabdate;
	}
	public void setGrabdate(String grabdate) {
		this.grabdate = grabdate;
	}
	public Long getTotal() {
		return total;
	}
	public void setTotal(Long total) {
		this.total = total;
	}
	public Long getSuccessNum() {
		return successNum;
	}
	public void setSuccessNum(Long successNum) {
		this.successNum = successNum;
	}
	public Long getFailNum() {
		return failNum;
	}
	public void setFailNum(Long failNum) {
		this.failNum = failNum;
	}

	public Long getActualNum() {
		return actualNum;
	}
	public void setActualNum(Long actualNum) {
		this.actualNum = actualNum;
	}

	public Long getStatus() {
		return status;
	}
	public void setStatus(Long status) {
		this.status = status;
	}

	public Long getGrabChannelID() {
		return grabChannelID;
	}
	public void setGrabChannelID(Long grabChannelID) {
		this.grabChannelID = grabChannelID;
	}


	//private static StatisticsTaskEntityRepository statisticsTaskEntityRepository = InstanceFactory.getInstance(StatisticsTaskEntityRepository.class);
	
	private static StatisticsTaskEntityRepository getStatisticsTaskEntityRepository(){
		return InstanceFactory.getInstance(StatisticsTaskEntityRepository.class);
	}
	/**
	 * @return查询所有
	 */
	public List<StatisticsTaskEntity> getStatisticsTaskEntity(String grab_channel,String startTime,String endTime){
		return getStatisticsTaskEntityRepository().getStatisticsTaskEntity(grab_channel,startTime,endTime);
	}
	
	/**
	 * @return条件查询
	 */
	public List<StatisticsTaskEntity> getStatisticsTaskByCondition(String grabchannel,String beginTime,String endTime,String seachByType,String SymbolType,Long num){
		return getStatisticsTaskEntityRepository().getStatisticsTaskByCondition(grabchannel, beginTime, endTime, seachByType, SymbolType, num);
	}
	@Override
	public Serializable getId() {
		return null;
	}
	public Long getWaiting() {
		return waiting;
	}
	public void setWaiting(Long waiting) {
		this.waiting = waiting;
	}
	public long getStarting() {
		return starting;
	}
	public void setStarting(long starting) {
		this.starting = starting;
	}


	@Override
	public boolean isNew() {
		return getId() == null ;
	}

	@Override
	public boolean existed() {
		if (isNew()) {
			return false;
		}
		return getRepository().exists(getClass(), getId());
	}

	@Override
	public boolean notExisted() {
		return ! existed();
	}
	
	@Override
	public boolean existed(String propertyName, Object propertyValue) {
		List<?> entities = getRepository().find(QuerySettings.create(getClass()).eq(propertyName, propertyValue)); 
		return !(entities.isEmpty());
	}
}
